<?php
/**
 * Created by PhpStorm.
 * User: Shen
 * Date: 2016/6/23
 * Time: 22:01
 */
include_once 'database.php';

function getPathCate($cateid){
    $sql = "SELECT *,concat(path,',',id) AS fullpath FROM likecate WHERE id = $cateid";
    $res = mysql_query($sql);
    $row = mysql_fetch_assoc($res);
    $ids = $row['fullpath'];
    $sql = "SELECT * FROM likecate WHERE id IN ($ids) ORDER BY id ASC";
    $res = mysql_query($sql);
    $result = array();
    while ($row=mysql_fetch_assoc($res)){
        $result[] = $row;
    }
    return $result;
}


function display($cateId,$link='cate.php?cid='){
    $res = getPathCate($cateId);
    $str = '';
    foreach ($res as $key => $val) {
        $str .= "<a href='{$link}{$val['id']}'>{$val['catename']}</a>>";
    }
    return $str;
}

echo display(4);